//
//  WebSchemaDelegate.swift
//  MobileRTCSwiftSample
//
//  Created by Lil on 2018/12/1.
//  Copyright © 2018 Zoom Video Communications, Inc. All rights reserved.
//

import Foundation

protocol WebSchemaDelegate:NSObjectProtocol {
    func onHandleUrl(params:[String:Any]?,type:OneRole)
}

class WebURL: NSObject {
    //根据scheme获取参数字典
    static func getSchemeToDic(_ url: URL) -> Dictionary<String, Any> {
        if(url.absoluteString.contains("?")){
            var dict:Dictionary<String,Any> = [:]
            let datas = url.absoluteString.components(separatedBy: "?")
            if(datas.count > 1){
                let urlparams = datas[1].components(separatedBy: "&")
                for (_,keyvalue) in urlparams.enumerated(){
                    let temparr : [String] = keyvalue.components(separatedBy: "=")
                    let value = (temparr[1] == "") ? "":temparr[1]
                    let key   = temparr[0]
                    
                    dict.updateValue(value.removingPercentEncoding!, forKey: key)
                }
                return dict
            }
        }
        return [:]
    }
}
